<template>
  <el-dialog :title="this.$parent.tabtitle" :visible.sync="addFormVisible" width="30%">
    <el-form label-width="110px" label-position="left">
      <el-form-item label="名称">
        <el-input v-model="adminValue.admin_name" style="width:300px"></el-input>
      </el-form-item>
      <el-form-item label="账号">
        <el-input v-model="adminValue.username" style="width:300px"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="adminValue.password" style="width:300px"></el-input>
      </el-form-item>
      <el-form-item label="确认密码">
        <el-input v-model="adminValue.repass" style="width:300px"></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="adminValue.status" placeholder="请选择">
          <el-option label="启用" value="1"></el-option>
          <el-option label="禁用" value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="角色">
        <el-checkbox-group v-model="adminValue.role_id">
          <el-checkbox v-for="item in roleList" :label="item.id" :key="item.id">{{item.display_name}}</el-checkbox><br />
        </el-checkbox-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="setAdmin">确认</el-button>
        <el-button @click.native="addFormVisible = false">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
    export default {
      name: "admindialog",
      data(){
        return{
          addFormVisible : false,
          adminValue : {
            role_id : []
          },
          roleList: []
        }
      },
      mounted(){
        this.getRoleList();
      },
      methods:{
        //获取角色列表
        async getRoleList(){
          let params = {
            user_token: window.localStorage.getItem('user_token'),
          }
          const res = await this.$api.getRoleList(params);
          if (res.data.level == 'success'){
            this.roleList = res.data.data;
          }else {
            this.$message({
              message: res.data.message,
              type: 'warning'
            })
          }
        },
        //提交添加/修改
        setAdmin(){
          this.$parent.setAdmin();
        }
      },
      watch: {
        'addFormVisible': function (newVal) {
          if (newVal == false){
            this.adminValue = {
              role_id : []
            }
          }
        }
      }
    }
</script>

<style scoped>

</style>
